import request from '@/utils/request'

// 查询充值记录列表
export function listRecord(query) {
  return request({
    url: '/checksystem/record/list',
    method: 'get',
    params: {
      ...query,
      orderByColumn: 'transferTime',
      isAsc: 'desc'
    }
  })
}

// 查询充值记录详细
export function getRecord(id) {
  return request({
    url: '/checksystem/record/' + id,
    method: 'get'
  })
}

/**
 * 新增充值记录
 * @param {Object} data 充值记录数据
 * @param {number} data.userId - 用户ID
 * @param {string} data.phone - 手机号
 * @param {number} data.amount - 充值金额
 * @param {string} data.packageDetails - 套餐详情JSON字符串，包含price, points, duration, baseDate等字段
 * @param {string} data.transferTime - 转账时间
 * @param {string|number} data.isDeleted - 删除标记
 * @returns {Promise} 请求结果
 */
export function addRecord(data) {
  // 转换字段名以匹配后端接收格式
  const transformedData = {
    userId: data.userId,
    phone: data.phone,
    amount: data.amount,
    packageDetails: data.packageDetails,
    transferTime: data.transferTime,
    isDeleted: data.isDeleted === 'Y' ? 'Y' : 'N',
  };
  
  return request({
    url: '/checksystem/record',
    method: 'post',
    data: transformedData
  })
}

// 修改充值记录
export function updateRecord(data) {
  return request({
    url: '/checksystem/record',
    method: 'put',
    data: data
  })
}

// 删除充值记录
export function delRecord(id) {
  return request({
    url: '/checksystem/record/' + id,
    method: 'delete'
  })
}
